using System;
using JetBrains.Annotations;
using Kaleida.ServiceMonitor.Framework;
using Kaleida.ServiceMonitor.Model.Runtime;

namespace Kaleida.ServiceMonitor.Model.ScriptDirectives
{
    public class NameDirective : IScriptDirective
    {
        private readonly string name;

        public NameDirective([NotNull] string name)
        {
            if (name == null) throw new ArgumentNullException("name");
            if (name.Trim() == "") throw new ArgumentException("Cannot be blank", "name");

            this.name = name;
        }

        public CompiledNode Apply([NotNull] CompiledScriptModule module)
        {
            if (module == null) throw new ArgumentNullException("module");

            module.Name = name;
            return new CompiledNode(module);
        }
    }
}